package org.glut.backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.glut.backend.domain.Cinema;
import org.glut.backend.service.impl.CinemaServiceImpl;
import org.glut.backend.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  前端控制器
 *
 * @author wubinbin
 * @since 2025-08-02 14:04
 */
@RestController
@Slf4j
public class CinemaController {
   @Autowired
   private CinemaServiceImpl cinemaService;

   @Autowired
   RedisUtil redisUtil;

  @PostMapping("/public/cinema/query")
    public ResponseEntity<List<Object>> cinemaquery(@RequestBody Cinema cinema) {
      log.info("影院查询");

      QueryWrapper<Cinema> cinemaQueryWrapper = new QueryWrapper<>(Cinema.class);
      String key="cinema:query";
      List cinemaList = null;

      if(!redisUtil.hasKey(key)){
          List _cinemaList = cinemaService.list(cinemaQueryWrapper);
          if(!CollectionUtils.isEmpty(_cinemaList)){
              //缓存
              redisUtil.lSet(key,_cinemaList);
              return ResponseEntity.ok(_cinemaList);
          }
      }else{
          cinemaList =redisUtil.lGet(key,0,-1);
      }
      return ResponseEntity.ok(cinemaList);
  }

}
